package pers.zff.web.util;

import java.io.IOException;
import java.io.InputStream;
import org.apache.http.HttpResponse;



public class PerUtil {
	
	/**
	 * @Title: randomNum   
	 * @Description:
	 * @param: @param size
	 * @param: @return      
	 * @return: int      
	 * @throws
	 */
	public static int randomNum(int size){
		return (int) Math.random()*size;
	}
	
	/**
	 * @Title: responseOutWithJson   
	 * @Description:
	 * @param: @param response
	 * @param: @param responseObject
	 * @param: @return      
	 * @return: JSONObject      
	 * @throws
	 */
	public static String responseOutWithJson(HttpResponse response){
		InputStream inputStream = null;
		String result = null;
		try {
			inputStream = response.getEntity().getContent();
			result = HttpUtils.getJsonStringFromGZIP(inputStream);
		} catch (UnsupportedOperationException | IOException e) {
			e.printStackTrace();
		}
		return result;
	}
	
	/**
	 * @Title: getRandomNum   
	 * @Description: 根据需要判断返回4位、5位、6位的随机数
	 * @param: @param digit
	 * @param: @return      
	 * @return: int      
	 * @throws
	 */
	public static int getRandomNum(int digit){
		if(digit==4){
			return (int)((Math.random()*9+1)*1000);
		}else if(digit==5){
			return (int) ((Math.random()*9+1)*10000);
		}else if(digit==6){
			return (int)((Math.random()*9+1)*100000);
		}
		return 0;
	}
}
